package what.basic.list;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import java.awt.event.*;
public class Jlistselectionlistener {
	Jlistselectionlistener(){
		JFrame jf=new JFrame("Jlistselectionlistener");
		Container cp=jf.getContentPane();
		cp.setLayout(new BorderLayout());
		final String[] s={"american","japan","china","france"};
		final JList lst=new JList(s);
		 final JLabel lbl=new JLabel();
		
		
		lst.setVisibleRowCount(3);
		lst.setBorder(BorderFactory.createTitledBorder("which country do you like"));
		lst.addListSelectionListener(new ListSelectionListener(){
			public void valueChanged(ListSelectionEvent e) {
				int t=0;
				String st="your current selection:";
				int[] in=lst.getSelectedIndices();
				for(int i=0;i<in.length;i++){
					t=in[i];
					st=st+s[t]+" ";
				}
				lbl.setText(st);
			}
			
		});
		cp.add(lbl,BorderLayout.NORTH);
		cp.add(new JScrollPane(lst),BorderLayout.CENTER);
		jf.pack();
		jf.show();
		jf.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
	}
	public static void main(String[] args) {
		new Jlistselectionlistener();

	}

}
